# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter

import pandas as pd

class ScrapyZssq38Pipeline:

    def __init__(self):
        self.df = pd.DataFrame(columns=['name','author','bookType','desc','popularity','readerKeep'])

    def process_item(self, item, spider):
        # 转成series对象才可以操作
        series = pd.Series(item)
        self.df = self.df.append(series,ignore_index=True)

        return item

    def close_spider(self,spider):
        self.df.to_excel('zssq.xlsx',index=False)